//
//  AudioRecorderV.m
//  MGameTribe
//
//  Created by 杨敏 on 13-12-5.
//  Copyright (c) 2013年 YangMin. All rights reserved.
//

#import "AudioRecorderV.h"
#import "ConstantHeader.h"
#import "Tool.h"

@interface AudioRecorderV()<AnimationViewDelegate>


@end

@implementation AudioRecorderV

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor=ColorWithRGB(232, 233, 232);
        self.clipsToBounds=YES;
        
        CGFloat boarderGap_hori =8;
        
        UIImage *deleteImg_norm=ImageWithName(@"btn_remove_audio_norm", @"png", NO);
        UIImage *deleteImg_high=ImageWithName(@"btn_remove_audio_high", @"png", NO);
        self.deleteBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        _deleteBtn.frame=CGRectMake(boarderGap_hori, boarderGap_hori, deleteImg_norm.size.width, deleteImg_norm.size.height);
        _deleteBtn.titleLabel.font=[UIFont systemFontOfSize:13];
        [_deleteBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_deleteBtn setBackgroundImage:deleteImg_norm forState:UIControlStateNormal];
        [_deleteBtn setBackgroundImage:deleteImg_high forState:UIControlStateHighlighted];
        [self addSubview:_deleteBtn];

        CGFloat x_status=GetEndXWithView(_deleteBtn)+5;
        
        self.statusLb=[[UILabel alloc]init];
        _statusLb.frame=CGRectMake(x_status, boarderGap_hori,CGRectGetWidth(self.frame)-x_status*2, 21);
        _statusLb.font=[UIFont systemFontOfSize:FontSize_DefaultListTitle];
        FitLableHeightWithLabel(_statusLb);
        _statusLb.backgroundColor=[UIColor clearColor];
        _statusLb.textColor=[UIColor darkGrayColor];
        _statusLb.textAlignment=NSTextAlignmentCenter;
        [self addSubview:_statusLb];
        
     
        CGFloat controlBtnGap=boarderGap_hori*2;
        UIImage *controlImg_norm=ResizeImage(ImageWithName(@"btn_audio_record_normal", @"png", NO), 8, 8, 0, 0);
        UIImage *controlImg_high=ResizeImage(ImageWithName(@"btn_audio_record_high", @"png", NO), 8, 8, 0, 0);
        CGFloat controlBtnHeight=controlImg_norm.size.height;

        self.recordBtn=[DoubleFaceButton buttonWithType:UIButtonTypeCustom];
        _recordBtn.frame=CGRectMake(controlBtnGap, CGRectGetHeight(self.frame)-boarderGap_hori-controlImg_norm.size.height, CGRectGetWidth(self.frame)-controlBtnGap*2, controlBtnHeight);
        _recordBtn.titleLabel.font=[UIFont systemFontOfSize:FontSize_DefaultListContent];
        [_recordBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _recordBtn.faceOne_norm=controlImg_norm;
        _recordBtn.faceOne_high=controlImg_high;
        [_recordBtn showBacgroundImageWith:0];
        [self addSubview:_recordBtn];
        
        NSMutableArray *images =[NSMutableArray arrayWithCapacity:31];
        for (int i =0;  i<8;i++) {
            NSString *imageName=[NSString stringWithFormat:@"voice_record_feedback0%d",i];
            UIImage *image =ImageWithName(imageName, @"png", NO);
            
            if (image) {
                [images addObject:image];
            }
        }
        //DLog(@"images.count:%d",images.count);
        
        UIImage *firstImg=getSafeObjectAtIndex(0, images);
        CGFloat midHeight=GetYWithView(_recordBtn)-GetEndYWithView(_statusLb);
        
        self.animationView = [[AnimationView alloc]initWithFrame:CGRectMake((CGRectGetWidth(self.frame)-firstImg.size.width)/2, GetEndYWithView(_statusLb)+(midHeight-firstImg.size.height)/2, firstImg.size.width, firstImg.size.height) images:images];
        _animationView.delegate=self;
        _animationView.backgroundColor=[UIColor clearColor];
        [self addSubview:_animationView];

        UIImage *playImg_norm=ImageWithName(@"ic_voice_playback_normal", @"png", NO);
        UIImage *playImg_high=ImageWithName(@"ic_voice_playback_press", @"png", NO);
        self.playbtn=[DoubleFaceButton buttonWithType:UIButtonTypeCustom];
        _playbtn.faceOne_norm=playImg_norm;
        _playbtn.faceOne_high=playImg_high;
        _playbtn.frame=CGRectMake((CGRectGetWidth(self.frame)-playImg_high.size.width)/2,GetEndYWithView(_statusLb)+(midHeight-playImg_norm.size.height)/2, playImg_high.size.width, playImg_high.size.height);
        CenterTheButton(_playbtn);
        [_playbtn showImageWith:0];
        [self addSubview:_playbtn];
        
    }
    return self;
}


@end
